/*
** 1565.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Thu Sep 25 20:50:23 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

/* #include "1565.h" */
#include <stdio.h>
#include <string.h>

int main()
{
     char bt[33];
     int i, len;
     unsigned int tmp;
     unsigned int power2[32];
     for(power2[0] = 1, i = 1; i < 32; i++)
	  power2[i] = power2[i - 1] * 2;
     
     while(scanf("%s", bt)){
	  if (bt[0] == '0') break;
	  tmp = 0;
	  len = strlen(bt);
	  for(i = 0; i < len; i++)
	       if (bt[i] == '1')
		    tmp += power2[len - i] - 1;
	       else if (bt[i] == '2')
		    tmp += (power2[len - i] - 1)*2;
	  printf("%d\n", tmp);
     }
     return 0;
}
